var now_type;
$(function(){

    var role=$("#role").val();
    now_type =$(".active").attr('data-type');
    // 选择身份
    $.post($('input[name="url"]').val() + "Home/My_feedback/checkRole", {}, function(data) {
        if (data.status) {
            var t = JSON.parse(data.v);
            if(t.length>1){
                var dialog=$(document).dialog({
                    type: 'confirm',                    
                    style: 'ios', 
                    content: '请选择查看身份',
                    buttons: [{
                        name: t[0][1],
                        callback: function() {
                            $("#role").val(t[0][0]);
                            dialog.close();
                            getList();
                        }
                    }, {
                        name: t[1][1],
                        callback: function() {
                            $("#role").val(t[1][0]);
                            dialog.close();
                            getList();
                        }
                    }]
                });
            }else{
                $("#role").val(t[0][0]);
                getList();
            }
        }
    }, "json");   


    // tab切换
    $("#myTab li").click(function(event) {
        $(this).tab('show');
        now_type =$(".active").attr('data-type');
        getList();
    });

    
})

function gotoDetail(t) {
    var id=$(t).attr('data-id');
    window.location=$("input[name='url']").val()+'Home/My_feedback/gotoDetail1/'+now_type+'/'+id;
}


function getList(){
    var feedback_type=$(".active").attr('data-type');
    var role=$("#role").val();
    $.ajax({
        url: $("input[name='url']").val()+'Home/My_feedback/getDatas/'+feedback_type+'/'+role,
        type: 'POST',
        dataType: 'json',
        success:function(data){
            if(data.status){
                var t =JSON.parse(data.v);
                var html ="";
                if (t==null||t=='') {
                    html="还未提交过反馈！";
                }

                $.each(t, function(k, v) {
                    html=html+"<li class='list-group-item' data-id='"+v['id']+"' onclick='gotoDetail(this)'><div class='row'><div class='col-xs-7'>"+v['status']+"</div><div class='col-xs-4'>"+v['created']+"</div></div><div  onclick='gotoDetail(this)' data-id='"+v['id']+"'>反馈类型："+v['type']+"</div><div  onclick='gotoDetail(this)' data-id='"+v['id']+"' class='feed_content'>反馈内容："+v['content']+"</div></li>";
                    // html=html+"<li class='list-group-item'><div class='row'><div class='col-xs-4'>"+v['created']+"</div><div class='col-xs-7'>"+v['content']+"</div></div></li>";
                });
                $(".list-group").html(html);
            }   
        }
    }) 
}
